package com.example.web;

import com.example.entity.Customer;
import com.example.repository.CustomerRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Administrator on 2017/3/2 0002.
 * 使用spring data-neo4j
 */
@RestController
@RequestMapping("/neo4j")
public class Neo4jController {

    @Autowired
    private CustomerRepository customerRepository;

    @RequestMapping("/test")
    public Object test() {
        this.customerRepository.deleteAll();
        this.customerRepository.save(new Customer("Alice", "Smith"));
        this.customerRepository.save(new Customer("Bob", "Smith"));
        System.out.println("Customers found with findAll():");
        System.out.println("-------------------------------");
        for (Customer customer : this.customerRepository.findAll()) {
            System.out.println(customer);
        }
        System.out.println();

        // fetch an individual customer
        System.out.println("Customer found with findByFirstName('Alice'):");
        System.out.println("--------------------------------");
        System.out.println(this.customerRepository.findByFirstName("Alice"));

        System.out.println("Customers found with findByLastName('Smith'):");
        System.out.println("--------------------------------");
        for (Customer customer : this.customerRepository.findByLastName("Smith")) {
            System.out.println(customer);
        }
        return null;
    }


}
